package com.ruoyi.cms.blog.controller;

import com.ruoyi.cms.blog.domain.CmsUserAmountLog;
import com.ruoyi.cms.blog.service.ICmsUserAmountLogService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

/**
 * 用户消费记录Controller
 *
 * @author ruoyi
 * @date 2025-04-13
 */
@RestController
@RequestMapping("/cms/user/amount")
public class CmsUserAmountLogController extends BaseController {
    @Autowired
    private ICmsUserAmountLogService cmsUserAmountLogService;

    /**
     * 查询用户消费记录列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CmsUserAmountLog cmsUserAmountLog) {
        startPage();
        List<CmsUserAmountLog> list = cmsUserAmountLogService.selectCmsUserAmountLogList(cmsUserAmountLog);
        return getDataTable(list);
    }

    /**
     * 导出用户消费记录列表
     */
    @Log(title = "用户消费记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsUserAmountLog cmsUserAmountLog) {
        List<CmsUserAmountLog> list = cmsUserAmountLogService.selectCmsUserAmountLogList(cmsUserAmountLog);
        ExcelUtil<CmsUserAmountLog> util = new ExcelUtil<CmsUserAmountLog>(CmsUserAmountLog.class);
        util.exportExcel(response, list, "用户消费记录数据");
    }

    /**
     * 获取用户消费记录详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(cmsUserAmountLogService.selectCmsUserAmountLogById(id));
    }

    /**
     * 新增用户消费记录
     */
    @Log(title = "用户消费记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsUserAmountLog cmsUserAmountLog) {
        return toAjax(cmsUserAmountLogService.insertCmsUserAmountLog(cmsUserAmountLog));
    }

    /**
     * 修改用户消费记录
     */
    @Log(title = "用户消费记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsUserAmountLog cmsUserAmountLog) {
        return toAjax(cmsUserAmountLogService.updateCmsUserAmountLog(cmsUserAmountLog));
    }

    /**
     * 删除用户消费记录
     */
    @Log(title = "用户消费记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cmsUserAmountLogService.deleteCmsUserAmountLogByIds(ids));
    }


}
